#include <stdio.h>
#include <stdlib.h>

#define Max(a,b) ((a)>(b)?(a):(b))

int totalFruit(int* fruits, int fruitsSize) {
    int *flag=calloc(fruitsSize,sizeof(int));
    int typeCount=0,maxFruit=0,left=0,right=0;    
    for( ; right < fruitsSize; right++ ){
        if( flag[ fruits[right] ]++ == 0 )
            typeCount++;
        while( typeCount > 2 ){
            if( --flag[ fruits[left++] ] == 0 )
                typeCount--;
        }
        maxFruit=Max(maxFruit,right-left+1);
    }
    return maxFruit;
}

int main(){
    //int f[]={1,2,1};
    //int f[]={0,1,2,2};
    //int f[]={1,2,3,2,2};
    int f[]={3,3,3,1,2,1,1,2,3,3,4};
    printf("%d\n",totalFruit(f,sizeof(f)/sizeof(int)));
    return 0;
}
